package com.baymax.study.tuLing.bio;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * IO流学习
 *
 * @author Baymax Gu
 * @since 2024-09-11
 */
public class Demo01_CreateFile {
    public static void main(String[] args) throws IOException {
        File file = new File("d:\\mytemp");
        if (!file.exists()) {
            file.mkdir();
        }
        File txtFile = new File(file, "hello.txt");
        if (txtFile.exists()) {
            System.out.println("文件已存在");
        } else {
            txtFile.createNewFile();
        }
        writeText(txtFile);
    }

    private static void writeText(File txtFile) throws IOException {
        FileOutputStream fos = new FileOutputStream(txtFile);
        fos.write("hello world".getBytes());
        fos.write("\n".getBytes());
        fos.write("你好，IO流".getBytes());
        fos.close();
    }
}
